<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 1、导入依赖 -->
  <link rel="stylesheet" href="https://lib.baomitu.com/leaflet/1.9.4/leaflet.css">
  <script src="https://lib.baomitu.com/leaflet/1.9.4/leaflet.js"></script>
  <style>
    #map {
      width: 100vw;
      height: 100vh;
    }
  </style>
</head>

<body>
  <!-- 2、创建地图挂载点 -->
  <div id="map"></div>
</body>
<script>
  const url = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png'
  var layer = L.tileLayer(url, {
    maxZoom: 19,
    attribution: '© OpenStreetMap'
  })
  // 3.创建地图实例
  const map = L.map('map', {
    center: [30, 114],
    zoom: 8,
    layers: [layer]
  })
  console.log(map);

  // 地图点击事件
  map.on('click', (e) => {
    console.log(e);
    const { lat, lng } = e.latlng

    map.flyTo({
      lat, lng // 目标地理位置的纬度和经度
    }, 8)
  }) // 设置地图缩放级别为8
</script>

</html>